import { reactive } from "vue";
import { getAllAccountTreeApi, getRegistrantTreeApi } from "@/api/financialManagement/receivable/waterVerification";
import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";
import { getAllCompanyApi } from "@/api/managementCenter/departmentPersonnel";
import { TreeSelect } from "ant-design-vue";
const SHOW_CHILD = TreeSelect.SHOW_CHILD;
export const searchItemList: Array<SuperSearch.SearchItem> = [
  // {
  //   type: "input",
  //   label: "流水单号",
  //   keyName: "orderNums",
  //   placeholder: "支持批量(空格/逗号隔开)"
  // },
  // {
  //   type: "input",
  //   label: "客户简称",
  //   keyName: "customerNames",
  //   placeholder: "支持批量(空格/逗号隔开)"
  // },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "收款账户",
    keyName: "accountIdList",
    optConfig: {
      label: "name",
      value: "id",
      children: "deptAccounts"
    },
    optionsRequest: getAllAccountTreeApi,
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.map((t: any) => {
          return {
            name: t.deptName,
            id: t.deptId,
            ...t
          };
        });
      }
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "登记人",
    keyName: "createByList",
    optConfig: {
      label: "name",
      value: "id",
      children: "registerUsers"
    },
    optionsRequest: getRegistrantTreeApi,
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.map((t: any, index: number) => {
          return {
            id: index + 1,
            name: t.positionName,
            ...t
          };
        });
      }
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  {
    type: "daterange",
    label: "来款时间",
    keyName: "proceedsTime"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "经营单位",
    keyName: "companyIdList",
    optionsRequest: getAllCompanyApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },

    options: []
  })
];

export const tableColumn: Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem> = [
  {
    type: "checkbox",
    field: "checkbox",
    minWidth: "50"
  },
  {
    field: "orderNum",
    title: "订单号",
    minWidth: "150"
  },
  {
    field: "shortName",
    title: "客户简称",
    minWidth: "100"
  },
  {
    field: "customerName",
    title: "客户名称",
    minWidth: "100"
  },
  {
    field: "depositPrice",
    title: "来款金额",
    minWidth: "100"
  },
  {
    field: "proceedsAccount",
    title: "收款账户",
    minWidth: "140"
  },
  {
    field: "payerName",
    title: "来款方名称",
    minWidth: "120"
  },
  {
    field: "proceedsTime",
    title: "来款时间",
    minWidth: "135",
    formatter: "formatDate"
  },
  {
    field: "image",
    title: "来款图片",
    minWidth: "100",
    renderSlot: "image"
  },
  {
    field: "remark",
    title: "来款备注",
    minWidth: "140"
  },
  {
    field: "createName",
    title: "登记人",
    minWidth: "100"
  },
  {
    field: "createTime",
    title: "登记时间",
    minWidth: "135",
    formatter: "formatDate"
  },
  {
    field: "companyName",
    title: "经营单位",
    minWidth: "80"
  },
  {
    field: "action",
    title: "操作",
    minWidth: "140",
    fixed: "right",
    renderSlot: "action"
  }
];
